package com.chapter_5;

import java.util.Random;

/**
 * @Author: Timo
 * @Date: 2019/5/15 16:31
 * @Description: 客户
 */
public class EaterThread extends Thread {
    private final Table table;
    private final Random random;

    public EaterThread(String name, Table table, long seen) {
        super(name);
        this.table = table;
        this.random = new Random(seen);
    }


    @Override
    public void run() {
        try {
            while (true) {
                Thread.sleep(random.nextInt(1_1000));
                String cake = table.take();
                System.out.println("[Eater "+getName()+" take cake ]");
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
